package io.github.lee.app.unsplash.ui.main.home

import android.app.Application
import androidx.lifecycle.MutableLiveData
import dagger.hilt.android.lifecycle.HiltViewModel
import io.github.lee.app.unsplash.repository.TopicRepository
import io.github.lee.app.unsplash.repository.domain.Topic
import io.github.lee.core.vm.BaseViewModel
import javax.inject.Inject

@HiltViewModel
class HomeVM @Inject constructor(
    application: Application,
    private val repo: TopicRepository
) : BaseViewModel(application) {
    val topicList = MutableLiveData<List<Topic>>()


    fun topicList() {
        launchResult(
            {
                repo.topicList()
            },
            {
                error(null)
            }
        ) {
            topicList.postValue(it.data ?: emptyList())
        }

    }


}